package com.ck.juc;

import java.util.concurrent.CountDownLatch;

public class Vol {

    private volatile int number = 0;

    public void add(){
        number++;
    }

    public static void main(String[] args) throws InterruptedException {
        Vol vol = new Vol();
        CountDownLatch latch = new CountDownLatch(20);
        for(int i =0;i<20;i++){
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    for(int i =0;i<1000;i++){
                        vol.add();
                    }
                    latch.countDown();
                }
            });
            thread.start();
        }
        latch.await();
        System.out.println(vol.number);
    }

    public static Vol getInstance(){
        return test.INSTANCE.getInstance();
    }



    private enum test{

        INSTANCE;

        private final Vol vol;

        test(){
            vol = new Vol();
        }

        private Vol getInstance(){
            return vol;
        }
    }
}



